package com.ojoin.ojoin.eb_spider.service.catchdata;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ojoin.ojoin.eb_spider.dao.InventoryMapper;
import com.ojoin.ojoin.eb_spider.dao.VecodesMapper;
import com.ojoin.ojoin.eb_spider.domain.AssistCatchData;
import com.ojoin.ojoin.eb_spider.domain.BankCardCheck;
import com.ojoin.ojoin.eb_spider.domain.MeiMeiJiaYuan;
import com.ojoin.ojoin.eb_spider.listening.CatchDateListening;
import com.ojoin.ojoin.eb_spider.model.Goods;
import com.ojoin.ojoin.eb_spider.model.Inventory;
import com.ojoin.ojoin.eb_spider.model.Vecodes;
import com.ojoin.ojoin.eb_spider.service.WebDriverService;
import com.ojoin.ojoin.eb_spider.service.impl.SLDataCatchBaseServiceImpl;
import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.CommonUtils;
import com.ojoin.trade.common.utils.Config;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.utils.TimeUtils;
import com.ojoin.trade.common.utils.WaitUtil;
import com.ojoin.trade.common.utils.json.JSONUtils;

/**
 *
 *
 */

@Service
public class MeidiMeiMeiJiaYuanDataCatchServiceImpl extends SLDataCatchBaseServiceImpl {
	private static Logger log = LoggerFactory.getLogger(MeidiMeiMeiJiaYuanDataCatchServiceImpl.class);

	public List<CatchDateListening>  Listenings = new ArrayList<CatchDateListening>() ;
	
	/* private List<Goods> list = new ArrayList<>(); */
	
	@Autowired
	private VecodesMapper vecodesMapper;

	@Autowired
	private InventoryMapper inventoryMapper;

	/*
	 * @Autowired private GoodsMapper goodsMapper;
	 */

	private static Map<String, Map<String, List<String>>> map = new HashMap<String, Map<String, List<String>>>();

	private static Set<String> set = new HashSet<String>();

	{
		Map<String, List<String>> mp = new HashMap<String, List<String>>();
		List<String> li = new ArrayList<String>();
		li.add("陶瓷板");
		mp.put("外观类-外观破损", li);
		map.put("电磁炉", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("内锅");
		li.add("电热盘");
		mp.put("外观类-外观破损", li);
		map.put("电饭锅", mp);
		map.put("电饭煲", mp);
		map.put("方煲", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("外壳");
		mp.put("外观类-外观破损", li);
		map.put("电水壶", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("电热盘");
		li.add("上盖");
		mp.put("外观类-外观破损", li);

		map.put("电饼铛", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("内锅");
		li.add("发热盘");
		mp.put("外观类-外观破损", li);
		mp.put("外观类-外观损坏", li);
		map.put("电压力锅", mp);
		map.put("", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("搅拌杯");
		li.add("外壳");
		li.add("底盖");

		mp.put("外观类-外观破损", li);
		mp.put("外观类-外观损坏", li);

		map.put("榨汁机", mp);
		map.put("原汁机", mp);
		map.put("果汁机", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("外壳");
		li.add("内胆");
		mp.put("外观类-外观破损", li);
		map.put("豆浆机", mp);
		map.put("开水瓶", mp);
		map.put("电热水瓶", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("底座");
		mp.put("外观类-外观损坏", li);
		map.put("煎烤机", mp);

		mp = new HashMap<String, List<String>>();
		li = new ArrayList<String>();
		li.add("底座");
		mp.put("外观类-外观损坏", li);
		map.put("煎烤机", mp);
		set = map.keySet();

	}

	@Override
	public boolean isLoginSuccess() throws Exception {
		boolean loginflag = false;

		String username = this.getAssistCatchData().getStartMess().getPlatformUser().getUsername();
		String password = this.getAssistCatchData().getStartMess().getPlatformUser().getPassword();

		String loginUrl = this.getAssistCatchData().getStartMess().getPlatformInfo().getLoginUrl();

		loginflag = LoginByUserInfo(loginUrl, username, password);

		return loginflag;
	}

	@Override
	public boolean LoginByUserInfo(String baseUrl, String username, String password) {
		// 开始登陆
		//try {
			String indexUrl = Config.getProperty(MeiMeiJiaYuan.config, MeiMeiJiaYuan.indexUrl);

			this.getWebDriver().get(indexUrl);

			this.getWebDriver().sendKeys("id", "account", username);
			this.getWebDriver().sendKeys("id", "password", password);

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"signin\"]/div[3]/a");

		//} catch (Exception e) {
		//	LogUtils.info(log, e.getMessage());
		//}

		return this.getWebDriver().isLogin("https://cs.midea.com/c-css/views/css/desktop/index.jsp");
	}

	@Override
	public void catchData(AssistCatchData assistCatchData)  {
		

		try {
			super.init(assistCatchData);
			prepareCatchData();

			boolean flag = isLoginSuccess();

			if (flag) {
 
				List<Vecodes> list = vecodesMapper.selectBySubtimeIsNull("2016-12-25");
 
				open();

				if (!CommonUtils.isEmpty(list)) {
					for (Vecodes vecodes : list) {

						Inventory inventory = new Inventory();
						inventory.setCategorytype(vecodes.getGoodname());
						inventory.setDescMark(vecodes.getCategorytype());
						List<Inventory> li = inventoryMapper.selectByProdoct(inventory);

						if (li.size() < 1) {
							log.info("inventory["+JSONUtils.toJSONString(inventory)+"]");
							continue;
						}

						boolean success = doit(vecodes, li);
						if (success) {
							LogUtils.info(log, vecodes.getMallcode() + "成功");
						} else {
							LogUtils.info(log, vecodes.getMallcode() + "失败");
						}

						vecodes.setSubtime(new Date());
						vecodesMapper.updateBymallcodeSelective(vecodes);
					}
				}

			}

		} catch (Exception e) {
           log.error("",e);
			// 监听器启动
			try{
				closeCatchData(true, false);
			}catch(Exception e2){
				log.error("关闭异常", e2);
			}
			
			if(null != Listenings){
				for(CatchDateListening as:Listenings){
					as.reStart();
				}
			}
			
			LogUtils.error(log, e);
			

		} finally {
			// LogUtils。info(log, e.toString());
			LogUtils.info(log, "finally");
		}
	}

	/**
	 * 打开导航到填写信息页面
	 */
	public void open() {
		WaitUtil.waitTimeSeconds(2);
		// 打开第一级导航菜单
		this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"nav\"]/div[1]/div[1]/div[1]");
		WaitUtil.waitTimeSeconds(2);
		// 打开第二级导航菜单
		this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"tree0_1_span\"]");

	}

	/**
	 * 填写用户信息
	 */
	public void addUser() {
		//try {
			this.getWebDriver().switchToDefaultContent();
			// 打开第三极菜单
			WaitUtil.waitTimeSeconds(2);

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"tree0_2_span\"]");

			WebElement frame = this.getWebDriver().findElement(WebDriverService.xpath,
					"//*[@id=\"tabs\"]/div[2]/div[2]/div/iframe");

			this.getWebDriver().switchToframe(frame);

			this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"serviceUserMsgForm|1\"]/span/input[1]",
					Config.getProperty(MeiMeiJiaYuan.config, MeiMeiJiaYuan.username));

			this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"serviceUserMsgForm|2\"]/span/input[1]",
					Config.getProperty(MeiMeiJiaYuan.config, MeiMeiJiaYuan.phone));
			// *
			// 点击小三角，填写手机区号
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"serviceUserMsgForm|8\"]/span/span/a");

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"_easyui_combobox_i13_0\"]");

			this.getWebDriver().click(WebDriverService.CSS, "#_easyui_tree_13 > span.tree-title");

			// 双击选中区号地址
			this.getWebDriver().clickdblByJS(WebDriverService.ID, "_easyui_tree_25");

		//} catch (Exception e) {
		//	LogUtils.error(log, e);
	//	}

	}

	/**
	 * server request
	 */
	public void serverRequest(String category) {
		//try {

			// *
			// 一级业务点击 //*[@id="baseMsgForm|2"]/span/span/a[2]
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"baseMsgForm|2\"]/span/span/a[2]");

			if (!this.getWebDriver().IsDisplayed(WebDriverService.ID, "_easyui_tree_46")) {
				this.getWebDriver().click(WebDriverService.ID, "_easyui_tree_5");
			}

			WaitUtil.waitTimeSeconds(2);

			this.getWebDriver().click(WebDriverService.CSS,
					"body > div:nth-child(19) > div > ul >  li:nth-child(5) > ul > li:nth-child(1)");

			WaitUtil.waitTimeSeconds(2);

			// 产品品类

			this.getWebDriver().click(WebDriverService.xpath,
					"//*[@id=\"userDemandFormquickSearch_prodName\"]/span/span/a");

			WaitUtil.waitTimeSeconds(2);
			// 选中产品
			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[12]/div[2]/div/div[1]/div[2]/ul");

			addGoods(category);

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"datagrid-row-r2-2-1\"]/td[1]/div/input");
			// 确定

			this.getWebDriver().click(WebDriverService.xpath,
					"/html/body/div[12]/div[2]/div/div[2]/div/div[2]/a[2]/span/span[2]");

			// 服务请求

			/* 选中质量信息反馈 开始 */

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"userDemandForm|9\"]/span/a");

			// 获取根路径ul
			WebElement ul = this.getWebDriver().findElement(WebDriverService.xpath,
					"/html/body/div[15]/div[2]/div/div[1]/div/ul");

			WebElement ul1 = this.getWebDriver().findElement(ul, WebDriverService.CSS, "li ul");
			ul1.click();

			WebElement ul2 = this.getWebDriver().findElement(ul1, WebDriverService.CSS, "li ul");

			ul2.click();

			// 弹出框确定

			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[15]/div[2]/div/div[2]/div/div/a[3]");

			/* 选中质量信息反馈 结束 */

			// 提交
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"userDemandCommitBtn\"]/span/span");

			// 确定
			WaitUtil.waitTimeSeconds(1);
			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[38]/div[3]/a[1]");

			// 工单处理

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"serviceDispathchBtn\"]/span/span");

		//} catch (Exception e) {
		//LogUtils.error(log, e);
		//}

	}

	public void addGoods(String category) {

		List<WebElement> trs = this.getWebDriver().findElements(WebDriverService.CSS,
				"body > div:nth-child(13) > div.panel-body.panel-body-noborder.window-body.panel-noscroll > div > div.panel.layout-panel.layout-panel-center > div > div:nth-child(3) > div > div > div.datagrid-view > div.datagrid-view2 > div.datagrid-body > table tbody tr");

		for (WebElement tr : trs) {
			Goods goods = new Goods();
			List<WebElement> tds = this.getWebDriver().findElements(tr, WebDriverService.CSS, "td");

			String brand = tds.get(1).getText();
			String goodsCode = tds.get(2).getText();
			String goodscategory = tds.get(3).getText();
			String goodscategorycode = tds.get(4).getText();
			goods.setBrand(brand);
			goods.setGoodscategory(goodscategory);
			goods.setGoodscode(goodsCode);
			goods.setGoodscategorycode(goodscategorycode);
			if (category.contains(goods.getGoodscategory()) && "美的".equals(brand)) {
				tr.click();
				break;
			}
		}

		/*
		 * if(goodFlag){ goodsMapper.addGoodsBatch(list); goodFlag = false; }
		 */
	}

	public void dealOrder() {
		//try {
			// 接单人
			//
			this.getWebDriver().switchToDefaultContent();

			WebElement frame = this.getWebDriver().findElement(WebDriverService.xpath,
					"//*[@id=\"tabs\"]/div[2]/div[3]/div/iframe");

			this.getWebDriver().switchToframe(frame);

			this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"dispatchPublicForm1|0\"]/span/input[1]",
					Config.getProperty(MeiMeiJiaYuan.config, MeiMeiJiaYuan.receive));

			// 接单
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"btnReceiveOrder\"]/span/span");
			WaitUtil.waitTimeSeconds(1);
			// 弹出框确定
			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[29]/div[3]/a");

		//} catch (Exception e) {
		//	LogUtils.error(log, e);
		//}

	}

	public void dealDate() {
		//try {
			int count = 1 ;
			boolean flag = false;
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"dispatchPublicForm1|3\"]/span/span/a");
			
			while(count < 8){
				// 预约日期                    
				
				WaitUtil.waitTimeSeconds(2);
				// WebElement start =
				// this.getWebDriver().findElement(WebDriverService.xpath,
				// "//*[@id=\"dispatchPublicForm1|3\"]/span/input[1]");

				List<WebElement> tds = this.getWebDriver().findElements(WebDriverService.CSS,
						"body > div:nth-child(57) > div > div.datebox-calendar-inner.panel-noscroll > div > div.calendar-body > table tbody tr td");
				// this.getWebDriver().sendKeys(WebDriverService.xpath,
				// "//*[@id=\"dispatchPublicForm1|3\"]/span/input[1]",
				// TimeUtils.getCurDate());
				if (null != tds && tds.size() > 0) {
					Iterator<WebElement> it = tds.iterator();
					while (it.hasNext()) {
						WebElement td = it.next();
						String abbr = td.getAttribute("abbr");
						String time = abbr.replaceAll(",", "-");
						String etime = TimeUtils.getDateAfterDays(1).replaceAll("-0", "-");
						//log.info("etime:["+etime+"]-------time:["+time+"] ");
						if (time.equals(etime)) { 
							log.info("time:["+time+"] is click");
							td.click();
							flag = true;
							break;
						}

					}
					break;
				}else {
					count ++;
					log.info("tds is null");
				}
				
			}
			// 预约时间段

			if(!flag){
				throw new BusinessException("tds is null");
			}
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"dispatchPublicForm1|4\"]/span/span/a");

			List<WebElement> divs = this.getWebDriver().findElements(WebDriverService.CSS,
					"body > div:nth-child(58) > div div");
			
			if(null != divs && divs.size() >0 ){
				int x = (int) (Math.random() * divs.size());

				divs.get(x).click();

				this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"dispatchPublicForm1|8\"]/span/input[1]",
						"预约");

				// 预约

				this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"btnUnitAppoint\"]/span/span");

				for (int i = 38; i < 50; i++) {
					if (this.getWebDriver().IsExist(WebDriverService.xpath, "/html/body/div[" + i + "]/div[3]/a")) {
						this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[" + i + "]/div[3]/a");
					}
				}
				
				
			}
			

		//} catch (Exception e) {
			//LogUtils.error(log, e);
		//}

	}

	@Override
	public String catchSupplierName() throws BusinessException {
		initCompanyInfomation();
		String name = "";

		return name;
	}

	public void initCompanyInfomation() {

		// http://b2bi.gome.com.cn/gmol/sellVatInvQry/detail.hlt?invid=2041525

	}

	/**
	 * 派工工程师
	 */

	public void dispatching() {
		//try {
			// 派工工程师
			WaitUtil.waitTimeSeconds(2);
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"dispatchOrder\"]");

			WaitUtil.waitTimeSeconds(2);

			this.getWebDriver().click(WebDriverService.CSS,
					"body > div:nth-child(72) > div.panel-body.panel-body-noborder.window-body > div.panel.datagrid > div > div.datagrid-view > div.datagrid-view1 > div.datagrid-body > div > table tr:nth-child(1)");

			// 确定

			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[43]/div[2]/div[1]/a[2]");

			// 派工成功，确定
			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[47]/div[3]/a");

		//} catch (Exception e) {
		//	LogUtils.error(log, e);
		//}

	}

	/**
	 * 
	 * 反馈结果
	 * 
	 * @param oms
	 * @return
	 */

	public void feedbacResult() {
		//try {

			// 反馈结果
			WaitUtil.waitTimeSeconds(1);

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"dispatchPublicForm2|4\"]/span/a");

			WebElement ul = this.getWebDriver().findElement(WebDriverService.CSS,
					"body > div:nth-child(17) > div.panel-body.panel-body-noborder.window-body > div > div:nth-child(2) > ul");

			this.getWebDriver().findElement(ul, WebDriverService.CSS,
					"li:nth-child(4) > ul > li:nth-child(1) > ul >  li:nth-child(1)").click();
			;

			// 确定

			this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[2]/div[2]/div/div[3]/a[1]");

			// 反馈描述
			WebElement text = this.getWebDriver().findElement(WebDriverService.xpath,
					"//*[@id=\"dispatchPublicForm2|10\"]/span/textarea");

			String tx = "维修完毕";

			text.sendKeys(tx);

			// 工程师反馈

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"btnEngineerFeedback\"]");

			// 反馈成功确定

			this.getWebDriver().click(WebDriverService.CSS,
					"body > div.panel.window.messager-window > div.dialog-button.messager-button > a");

		//} catch (Exception e) {
		//	LogUtils.error(log, e);
		//}

	}

	/**
	 * 
	 * 档案录入
	 * 
	 * @param oms
	 * @return
	 */

	public void archivesInputClick() {
		//try {

			// 档案录入

			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"btnArchivesInsert\"]");

		//} catch (Exception e) {
		//	LogUtils.error(log, e);
		//}

	}

	/**
	 * 
	 * 档案录入
	 * 
	 * @param oms
	 * @return
	 */

	public void archivesInput(Vecodes vecodes, List<Inventory> li) {
		//try {

			// TODO 无备件 不消单
			this.getWebDriver().switchToDefaultContent();

			WebElement frame = this.getWebDriver().findElement(WebDriverService.xpath,
					"//*[@id=\"tabs\"]/div[2]/div[4]/div/iframe");

			this.getWebDriver().switchToframe(frame);
			WaitUtil.waitTimeSeconds(1);
			// 反馈描述
			String text = "维修完毕";

			this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"quality_info|16\"]/span/input[1]", text);

			String tx = "返销售单位";

			this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"quality_info|18\"]/span/input[1]", tx);
			
			int flag = 1;
			List<WebElement> li1 = null;
			while(flag < 3){
				// *[@id="tabs"]/div[2]/div[4]/div/iframe
				// 添加条码
				this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"machine_form|45\"]/span/input[1]",
						vecodes.getMallcode());

				// 增加通吗

				this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"machine_form|52\"]/span/input[1]");
				WaitUtil.waitTimeSeconds(1);
				this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"machine_form|52\"]/span/input[1]", "8");

				// 点击input ，促发更新

				this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"machine_form|46\"]/span/input[1]");

				// 反馈项目列表新增

				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"record_archives_panel\"]/div[3]/div/div[1]/div[4]/table/tbody/tr/td[1]/a");
				WaitUtil.waitTimeSeconds(1);
				// TODO 内容编码
				 li1 = this.getWebDriver().findElements(WebDriverService.CSS, "#_tree_content li");
				 
				 if(null == li1 || li1.size() == 0){
					 flag ++;
				 }else {
					 break;
				 }
			}

			

			int x1 = 0;

			while (x1 < li1.size()) {

				if (!li1.get(x1).getText().equals("产品检测") && !li1.get(x1).getText().equals("样机")
						&& li1.get(x1).getText().equals("产品包装不良")) {
					// WaitUtil.waitTimeSeconds(2);
					li1.get(x1).click();
					break;
				}

				x1++;
			}

			List<WebElement> li2 = this.getWebDriver().findElements(li1.get(x1), WebDriverService.CSS, "ul li");

			int x2 = (int) (Math.random() * li2.size());

			li2.get(x2).click();

			List<WebElement> li3 = this.getWebDriver().findElements(li2.get(x2), WebDriverService.CSS, "ul li");

			for (WebElement we : li3) {
				if (we.getText().indexOf("更换") > 0) {
					we.click();
					break;
				}
			}

			WaitUtil.waitTimeSeconds(2);

			/*
			 * //this.getWebDriver().sendKeys(WebDriverService.xpath,
			 * "//*[@id=\"_form_content|0\"]/span/input[1]",in.getSparepart());
			 * 
			 * // 查询
			 * 
			 * this.getWebDriver().click(WebDriverService.xpath,
			 * "//*[@id=\"_tree_grid_content\"]/div[4]/div[1]/div[2]/a[1]");
			 * 
			 */
			// 点击选择

			this.getWebDriver().click(WebDriverService.CSS,
					"#_tree_grid_content > div.panel.layout-panel.layout-panel-center > div.panel-body.layout-body > div.panel.datagrid.easyui-fluid > div > div.datagrid-view > div.datagrid-view2 > div.datagrid-body > table tr:nth-child(1)");

			// 确认

			this.getWebDriver().click(WebDriverService.xpath,
					"//*[@id=\"_tree_grid_content\"]/div[4]/div[1]/div[2]/a[2]");

			// 备件新增
			
			for(Inventory in :li){
				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"record_archives_panel\"]/div[4]/div/div[1]/div[4]/table/tbody/tr/td[1]/a");

				// 旧件代码查询

				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"datagrid-row-r7-2-0\"]/td[6]/div/table/tbody/tr/td/span/a");

				this.getWebDriver().sendKeys(WebDriverService.xpath, "//*[@id=\"_form_content|0\"]/span/input[1]",
						in.getSparepart());

				// 查询

				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"_tree_grid_content\"]/div[4]/div[1]/div[2]/a[1]");

				// 选择
				WaitUtil.waitTimeSeconds(2);
				this.getWebDriver().click(WebDriverService.CSS,
						"#_tree_grid_content > div.panel.layout-panel.layout-panel-center > div.panel-body.layout-body > div.panel.datagrid.easyui-fluid > div > div.datagrid-view > div.datagrid-view2 > div.datagrid-body > table tr:nth-child(1)");

				// 确定

				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"_tree_grid_content\"]/div[4]/div[1]/div[2]/a[2]");

				// 新件代码

				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"datagrid-row-r7-2-0\"]/td[10]/div/table/tbody/tr/td/span/span/a");
				// body > div:nth-child(30)

				for (int i = 29; i < 50; i++) {
					if (this.getWebDriver().IsExist(WebDriverService.CSS, "body > div:nth-child(" + i + ") > div > div ")) {
						this.getWebDriver().click(WebDriverService.CSS, "body > div:nth-child(" + i + ") > div > div ");
						break;
					}
				}

				// 证件类型

				this.getWebDriver().click(WebDriverService.xpath,
						"//*[@id=\"datagrid-row-r7-2-0\"]/td[13]/div/table/tbody/tr/td/span/span/a");

				for (int i = 29; i < 50; i++) {
					if (this.getWebDriver().IsExist(WebDriverService.CSS,
							"body > div:nth-child(" + i + ") > div > div:nth-child(2)")) {
						this.getWebDriver().click(WebDriverService.CSS,
								"body > div:nth-child(" + i + ") > div > div:nth-child(2)");
						break;
					}
				}
				
				
			}

			
			// 保存
			
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"btnSaveArchives\"]");
			

			/*// 提交审核

			
			this.getWebDriver().click(WebDriverService.xpath, "//*[@id=\"btnSaveorcommitArchives\"]");*/

			// 确定

			this.getWebDriver().click(WebDriverService.CSS,
					"body > div.panel.window.messager-window > div.dialog-button.messager-button > a:nth-child(1)");

			// 点击关闭
			try {
				this.getWebDriver().click(WebDriverService.xpath, "/html/body/div[24]/div[3]/a/span/span");
			} catch (Exception e) {
				LogUtils.info(log, "忽略异常");
			}

			// 更新库存
			for(Inventory in :li){
				in.setNum(in.getNum() - 1);
				inventoryMapper.updateByPrimaryKeySelective(in);
			} 
			

		//} catch (Exception e) {
		//	LogUtils.error(log, e);
		//}

	}

	public boolean doit(Vecodes vecodes, List<Inventory> li) {
		//try {
			addUser();

			serverRequest(vecodes.getGoodname());

			dealOrder();

			dealDate();

			dispatching();

			feedbacResult();

			archivesInputClick();

			archivesInput(vecodes, li);

		//} catch (Exception e) {
		//	LogUtils.info(log, e.getMessage());
		//	return false;
		//}

		return true;
	}

	@Override
	public boolean getUnpayAccountData() throws BusinessException {
		return true;

	}

	@Override
	public boolean getInstoreOrderData() throws BusinessException {

		return true;
	}

	@Override
	public boolean getOutstoreOrderData() throws BusinessException {
		// 送货记录
		// 对账单
		return true;
	}

	@Override
	public boolean getPayAccountData() throws BusinessException {
		return true;
	}

	@Override
	public BankCardCheck catchSupplierAccount() throws BusinessException {
		// TODO Auto-generated method stub
		return null;
	}

}
